﻿@{
    Layout = "~/Views/Shared/_FormWhite.cshtml";
}
<style type="text/css">
    img {
        max-height: 100px;
        max-width: 100px;
    }
</style>
<div class="wrapper animated fadeInRight">
    <form id="form" class="form-horizontal m">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>复检信息</h5>
                </div>
                <div class="ibox-content">
                    <div class="form-group">
                        <label class="col-sm-2 control-label">所属地区</label>
                        <div class="col-sm-4" id="Region" col="Region"></div>
                    </div>
                   
                    <div class="form-group" style="display:block;">
                        <label class="col-sm-2 control-label ">检测人员<font class="red"> *</font></label>
                        <div class="col-sm-4">
                            <select id="detectionUserId" col="DetectionUserId" class="form-control">
                                <option value="0">请选择</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label ">环保号牌<font class="red"> *</font></label>
                        <div class="col-sm-4">
                            <input id="huanBaoCode" col="HuanBaoCode" type="text" class="form-control" />
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label ">所有人<font class="red"> *</font></label>
                        <div class="col-sm-6">
                            <input id="ownerName" col="OwnerName" type="text" class="form-control" />
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label ">联系电话<font class="red"> *</font></label>
                        <div class="col-sm-4">
                            <input id="ownerTel" col="OwnerTel" type="text" class="form-control" />
                        </div>
                    </div>
                </div>
            </div>
           

         </div>
</form>
</div>

<script type="text/javascript">
    var id = ys.request("id");
    $(function () {
        bindDetectionUsers();
        $("#Region").ysComboBox({
            data: top.getDataDict("Region"),
            key: "DictValue",
            value: "DictValue",
            class: "form-control",
        });
        $("#huanBaoCode").change(function () {
            var value = $(this).val();
            if (value == "" || $.trim(value).length == 0) {
                return;
            }
            var data = {
                code: value
            };
            var queryUrl = '@Url.Content("~/YiDongYuan/Mechanics/GetFormJsonByCode")';
            ys.ajax({
                url: queryUrl,
                type: 'get',
                data: data,
                success: function (obj) {
                    if (obj && obj.Data) {
                        $('#ownerName').val(obj.Data.OwnerName);
                        $('#ownerTel').val(obj.Data.OwnerTel);
                    }
                    else {
                        $('#ownerName').val('');
                        $('#ownerTel').val('');
                    }
            }
        });

        });
        $('#form').validate({
            rules: {
                huanBaoCode: { required: true },
                ownerName: { required: true },
                ownerTel: { required: true },
            }
        });
    });
    function bindDetectionUsers() {
        var queryUrl = '@Url.Content("~/OrganizationManage/User/GetDetectionListJson")';
        ys.ajax({
            url: queryUrl,
            type: 'get',
            success: function (obj) {
                if (obj && obj.Data && obj.Data.length > 0) {
                    var html = '';
                    for (var i = 0; i < obj.Data.length; i++) {
                        html += '<option value="' + obj.Data[i].Id + '">' + obj.Data[i].RealName+'</option>';
                    }
                    $("#detectionUserId").append(html);
                }
            }
        });

    }

    function saveForm(index) {
        var data = {
            Region: $("#Region").ysComboBox('getValue'),
            DetectionUserId: $("#detectionUserId").val(),
            HuanBaoCode: $("#huanBaoCode").val(),
            OwnerName: $("#ownerName").val(),
            OwnerTel: $("#ownerTel").val()
        };
        if (data.DetectionUserId == 0) {
            ys.alertError('请选择审核人员');
            return;
        }
        if ($('#form').validate().form()) {
            ys.ajax({
                url: '@Url.Content("~/YiDongYuan/DetectionTask/RecheckFormJson")',
                type: 'post',
                data: data,
                success: function (obj) {
                    if (obj.Tag == 1) {
                        ys.msgSuccess(obj.Message);
                        parent.searchGrid();
                        parent.layer.close(index);
                    }
                    else {
                        ys.msgError(obj.Message);
                    }
                }
            });
        }
    }
</script>

